<!--页面主要内容-->
<main class="lyear-layout-content">

  <div class="container-fluid p-t-15">

    <div class="row">
      <div class="col-lg-12">
        <div class="card">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">用户管理</a>
            <a><cite>积分消费记录</cite></a>
          </span>
          <div class="card-toolbar d-flex flex-column flex-md-row">

            <form class="layui-form" id="layui-form" method="get" role="form" style="display: flex;">
              <input type="hidden" name="action" value="search">
              <select name="search" id="search" lay-filter="search">
                <option value="nickname">昵称</option>
              </select>
              <input type="text" name="title" placeholder="请选择搜索条件" autocomplete="off" class="layui-input">
              <button class="layui-btn layui-btn-primary" type="submit">搜索</button>
            </form>
          </div>
          <div class="card-body">
            <div class="table-responsive">
              <table class="table table-bordered">
                <thead>
                  <tr>
                    <th>编号</th>
                    <th>用户名</th>
                    <th>内容</th>
                    <th>金额</th>
                    <th>时间</th>
                    <th>操作</th>
                  </tr>
                </thead>
                <tbody>
                  {foreach $record as $key => $item}
                  <tr>
                    <td>{$key+1}</td>
                    <td>{$item.user.nickname}</td>
                    <td>{$item.content}</td>
                    <td>{$item.point}</td>
                    <td>{$item.createtime}</td>
                    <td>
                      {if condition="$item.flag == 0"}
                      <div class="btn-group">
                        <button class="btn btn-success btn_1" data-id="{$item.id}">通过</button>
                        <button class="btn btn-yellow btn_2" data-id="{$item.id}">不通过</button>
                      </div>
                      {elseif condition="$item.flag == 1"}
                      <div class="btn-group">
                        <button class="btn btn btn-info btn_1" disabled data-id="{$item.id}">已通过</button>
                      </div>
                      {elseif condition="$item.flag == 2"}
                      <div class="btn-group">
                        <button class="btn btn btn-primary btn_1" disabled data-id="{$item.id}">未通过</button>
                      </div>
                      {/if}
                    </td>
                  </tr>
                  {/foreach}
                </tbody>
              </table>
            </div>

            <!-- 分页 -->
            {$record->render()}
          </div>
        </div>
      </div>

    </div>

  </div>

</main>
<!--End 页面主要内容-->

<script>
  layui.use(['layer'], function () {
    var $ = layui.jquery,
      layer = layui.layer

    $('.btn_1').click(function () {
      let id = $(this).data('id')
      console.log(id)
      layer.confirm('确定通过审核？', { icon: 3, title: '提示' }, function (index) {

        $.ajax({
          type: 'post',
          url: `{:url('admin/user/recharge')}`,
          data: {
            id,
            action: 'recharge1'
          },
          dataType: 'json',
          success: function (res) {
            if (res.code == 1) {
              layer.msg(res.msg, { icon: 1, time: 1500 }, function (index) {
                // location.href = res.url
                location.reload()
                layer.close(index)
              })
            } else {
              layer.msg(res.msg, { icon: 2, time: 1500 }, function (index) {
                layer.close(index)
                location.reload()
              })
            }
          }
        })

        layer.close(index)
      })

    })

    $('.btn_2').click(function () {
      // console.log(2)
      let id = $(this).data('id')
      layer.confirm('确定不通过审核？', { icon: 3, title: '提示' }, function (index) {
        $.ajax({
          type: 'post',
          url: `{:url('admin/user/recharge')}`,
          data: {
            id,
            action: 'recharge2'
          },
          dataType: 'json',
          success: function (res) {
            if (res.code == 1) {
              layer.msg(res.msg, { icon: 1, time: 1500 }, function (index) {
                location.reload()
                layer.close(index)
              })
            } else {
              layer.msg(res.msg, { icon: 2, time: 1500 }, function (index) {
                layer.close(index)
                location.reload()
              })
            }
          }
        })
        layer.close(index)
      })
    })


  })
</script>

<style>
  .btn_1,
  .btn_2 {
    margin: 0 10px;
  }
</style>